package com.leetcode.algorithm.common;

import java.util.ArrayList;
import java.util.List;

public class ListUtils {

	public static boolean isEqual(List<Integer> list1, List<Integer> list2) {
		if (list1 == null || list2 == null) {
			return list1 == list2;
		}
		if (list1.size() != list2.size()) {
			return false;
		}
		for (int i = 0; i < list1.size(); i++) {
			if (!list1.get(i).equals(list2.get(i))) {
				return false;
			}
		}
		return true;
	}

	public static List<Integer> convertFromArr(int[] arr) {
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < arr.length; i++) {
			list.add(arr[i]);
		}
		return list;
	}

	public static boolean isEquivalent(List<Integer> list1, int[] arr) {
		return isEqual(list1, convertFromArr(arr));
	}

	public static boolean isTwoDimensionalEqual(List<List<Integer>> list1, List<List<Integer>> list2) {
		if (list1 == null || list2 == null) {
			return list1 == list2;
		}
		if (list1.size() != list2.size()) {
			return false;
		}
		for (int i = 0; i < list1.size(); i++) {
			if (!isEqual(list1.get(i), list2.get(i))) {
				return false;
			}
		}
		return true;
	}

	public static List<List<Integer>> convertFromTwoDimensionalArr(int[][] arr) {
		List<List<Integer>> list = new ArrayList<>();
		for (int i = 0; i < arr.length; i++) {
			list.add(convertFromArr(arr[i]));
		}
		return list;
	}

	public static boolean isEquivalent(List<List<Integer>> list1, int[][] arr) {
		return isTwoDimensionalEqual(list1, convertFromTwoDimensionalArr(arr));
	}

}
